package util;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 * Service Locator JEE
 */
public class ServiceLocator {

	private static InitialContext ctx;

	static {
		try {
			Properties env = new Properties();
			env.put(Context.INITIAL_CONTEXT_FACTORY,
					"org.jnp.interfaces.NamingContextFactory");
			env.put(Context.PROVIDER_URL, "jnp://localhost:1099/");
			env.put(Context.URL_PKG_PREFIXES,
					"org.jboss.naming:org.jnp.interfaces");

			ctx = new InitialContext(env);
		} catch (NamingException e) {
			throw new RuntimeException("Erro ao iniciar o localizador", e);
		}
	}

	public static Object getService(String name) throws NamingException {
		return ctx.lookup(name);
	}

}
